package com.hsyt.pfc.support.rpc;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:  返回结果
 * @ClassName: PageResult
 * @Package: com.hsyt.pfc.support.rpc
 * @Author: wangze@hsyuntai.com
 * @Date: 2018/08/14 9:26
 * @Copyright: 版权归 HSYUNTAI 所有
 */
public class PageResult<T> extends Result{

	private static final long serialVersionUID = -3343893909519199619L;

	/** 当前页数 */
	private int currentPageno;
	/** 总页数 */
	private int totalPageno;
	/** 是否还有下页 */
	private boolean nextPage;
	/** 总条数 */
	private int count;
	
	/** 返回结果的业务数据 */
	private List<T> content;

	private boolean result = true;

	private String message = "";

	private Long total = 0L;

	private List<T> rows = new ArrayList<T>();
	
	public int getCurrentPageno() {
		return currentPageno;
	}

	public void setCurrentPageno(int currentPageno) {
		this.currentPageno = currentPageno;
	}

	public int getTotalPageno() {
		return totalPageno;
	}

	public void setTotalPageno(int totalPageno) {
		this.totalPageno = totalPageno;
	}

	public List<T> getContent() {
		return content;
	}

	public void setContent(List<T> content) {
		this.content = content;
	}

	public boolean isNextPage() {
		return nextPage;
	}

	public void setNextPage(boolean nextPage) {
		this.nextPage = nextPage;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public boolean isResult() {
		return result;
	}

	public void setResult(boolean result) {
		this.result = result;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Long getTotal() {
		return total;
	}

	public void setTotal(Long total) {
		this.total = total;
	}

	public List<T> getRows() {
		return rows;
	}

	public void setRows(List<T> rows) {
		this.rows = rows;
	}

	public static <T> PageResult create(boolean result, String message, Long total, List<T>rows) {
		return new PageResult(result,message,total,rows);
	}

	public static <T> PageResult create(String message, Long total, List<T>rows) {
		return new PageResult(true,message,total,rows);
	}
	public static <T> PageResult create(Long total, List<T>rows) {
		return new PageResult(true,"",total,rows);
	}
	public static <T> PageResult create(List<T>rows) {
		return new PageResult(true,"", (rows == null)? 0L : rows.size(),rows);
	}
	public static <T> PageResult create(boolean result, String message) {
		return new PageResult(result,message,0L,null);
	}

	public PageResult() {
	}

	public PageResult(boolean result, String message, Long total, List<T> rows) {
		this.result = result;
		this.message = message;
		this.total = total;
		this.rows = rows;
	}

	@Override
	public String toString() {
		return "PageResult [currentPageno=" + currentPageno + "; totalPageno=" + totalPageno + "; nextPage=" + nextPage
				+ "; content=" + content + "; count=" + count + "]";
	}

}
